Repository navigation
Fix WebSocket 1009 close: permit, bad frames, server close - #2427
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
After a 1009, #2426 waits up to 10 seconds for the server to close, but releases the connection permit as soon as the close frame is sent. A server that never closes lets a reconnecting client go past
maxConnections. Frames the decoder already holds are still parsed, so a bad frame behind the big message makes Netty send a second close frame and close the connection first. The server's own close frame is dropped, so the client waits the full 10 seconds and reports 1006.Modification:
Keep the permit until the connection is closed. Replace the decoder after the 1009 with one that does not close on a protocol violation, and ignore decoder errors while waiting. Handle the server's close frame while waiting. Track the closing state with a channel attribute instead of scanning the pipeline for every frame.
Result:
maxConnectionsholds after a 1009, the client sends one close frame and leaves closing to the server, and a close frame from the server ends the wait with its code. A reconnect fromonErrorwithmaxConnectionsset is now refused until the old connection closes.